package org.ben.domain.strategypattern;

import java.math.BigDecimal;

import org.ben.constant.Constants;

public interface TaxPolicy<T extends Number> {
    public T calTax(T price);

    public static class OtherTaxPolicyImported implements TaxPolicy<BigDecimal> {
        public BigDecimal calTax(BigDecimal price) {
            Tax sTax = SalesTax.getInstance();
            Tax iTax = ImportTax.getInstance();

            BigDecimal resultTax = new BigDecimal(0,Constants.PRICE_TAX_PRECISION);
            resultTax = resultTax.add(price.multiply(BigDecimal.valueOf(sTax.getTaxRate())));
            resultTax = resultTax.add(price.multiply(BigDecimal.valueOf(iTax.getTaxRate())));
            return resultTax;
        }
    }

    public static class SalesTaxFreePolicyImported implements TaxPolicy<BigDecimal> {
        public BigDecimal calTax(BigDecimal price) {
            Tax iTax = ImportTax.getInstance();

            BigDecimal resultTax = new BigDecimal(0,Constants.PRICE_TAX_PRECISION);
            resultTax = resultTax.add(price.multiply(BigDecimal.valueOf(iTax.getTaxRate())));
            return resultTax;
        }
    }

    public static class SalesTaxFreePolicyNonImported implements TaxPolicy<BigDecimal> {
        public BigDecimal calTax(BigDecimal price) {
            BigDecimal resultTax = new BigDecimal(0,Constants.PRICE_TAX_PRECISION);
            return resultTax;
        }
    }

    public static class OtherTaxPolicyNonImported implements TaxPolicy<BigDecimal> {
        public BigDecimal calTax(BigDecimal price) {
            Tax sTax = SalesTax.getInstance();
            BigDecimal resultTax = new BigDecimal(0,Constants.PRICE_TAX_PRECISION);
            resultTax = resultTax.add(price.multiply(BigDecimal.valueOf(sTax.getTaxRate())));
            return resultTax;
        }
    }
}
